package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.MD5;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private UserAddressMapper userAddressMapper;
    @Override
    public UserInfo checkInfo(UserInfo userInfo) {
        return userInfoMapper.selectOne(new QueryWrapper<UserInfo>()
                .eq("login_name",userInfo.getLoginName())
                .eq("passwd", MD5.encrypt(userInfo.getPasswd())));

    }

    //查询当前用户的所有收货地址集合
    @Override
    public List<UserAddress> getUserAddress(String userId) {

        return userAddressMapper.selectList(new QueryWrapper<UserAddress>()
                .eq("user_id",userId));

    }
}
